/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entity;

import java.io.Serializable;
import java.math.BigInteger;
import java.util.Date;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Carito
 */
@Entity
@Table(name = "CITA")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Cita.findAll", query = "SELECT c FROM Cita c"),
    @NamedQuery(name = "Cita.findByIdcita", query = "SELECT c FROM Cita c WHERE c.citaPK.idcita = :idcita"),
    @NamedQuery(name = "Cita.findByAsunto", query = "SELECT c FROM Cita c WHERE c.asunto = :asunto"),
    @NamedQuery(name = "Cita.findByEstado", query = "SELECT c FROM Cita c WHERE c.estado = :estado"),
    @NamedQuery(name = "Cita.findByHorainicial", query = "SELECT c FROM Cita c WHERE c.horainicial = :horainicial"),
    @NamedQuery(name = "Cita.findByHorafinal", query = "SELECT c FROM Cita c WHERE c.horafinal = :horafinal"),
    @NamedQuery(name = "Cita.findByIdusuario", query = "SELECT c FROM Cita c WHERE c.citaPK.idusuario = :idusuario"),
    @NamedQuery(name = "Cita.findByIdempresa", query = "SELECT c FROM Cita c WHERE c.citaPK.idempresa = :idempresa")})
public class Cita implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected CitaPK citaPK;
    @Size(max = 150)
    @Column(name = "ASUNTO")
    private String asunto;
    @Size(max = 150)
    @Column(name = "ESTADO")
    private String estado;
    @Column(name = "HORAINICIAL")
    @Temporal(TemporalType.DATE)
    private Date horainicial;
    @Column(name = "HORAFINAL")
    @Temporal(TemporalType.DATE)
    private Date horafinal;
    @JoinColumns({
        @JoinColumn(name = "IDUSUARIO", referencedColumnName = "IDUSUARIO", insertable = false, updatable = false),
        @JoinColumn(name = "IDEMPRESA", referencedColumnName = "IDEMPRESA", insertable = false, updatable = false)})
    @ManyToOne(optional = false, fetch = FetchType.EAGER)
    private Usuario usuario;
    @JoinColumn(name = "IDPRIVACIDAD", referencedColumnName = "IDPRIVACIDAD")
    @OneToOne(fetch = FetchType.EAGER)
    private Privacidad idprivacidad;
    @JoinColumn(name = "IDPERIODICIDAD", referencedColumnName = "IDPERIODICIDAD")
    @OneToOne(fetch = FetchType.EAGER)
    private Periodicidad idperiodicidad;
    @OneToOne(cascade = CascadeType.ALL, mappedBy = "cita", fetch = FetchType.EAGER)
    private Repeticion repeticion;

    public Cita() {
    }

    public Cita(CitaPK citaPK) {
        this.citaPK = citaPK;
    }

    public Cita(BigInteger idcita, BigInteger idusuario, BigInteger idempresa) {
        this.citaPK = new CitaPK(idcita, idusuario, idempresa);
    }

    @XmlElement
    public CitaPK getCitaPK() {
        return citaPK;
    }

    public void setCitaPK(CitaPK citaPK) {
        this.citaPK = citaPK;
    }

    @XmlElement
    public String getAsunto() {
        return asunto;
    }

    public void setAsunto(String asunto) {
        this.asunto = asunto;
    }

    @XmlElement
    public String getEstado() {
        return estado;
    }

    public void setEstado(String estado) {
        this.estado = estado;
    }
    
    @XmlElement
    public Date getHorainicial() {
        return horainicial;
    }

    public void setHorainicial(Date horainicial) {
        this.horainicial = horainicial;
    }

    @XmlElement
    public Date getHorafinal() {
        return horafinal;
    }

    public void setHorafinal(Date horafinal) {
        this.horafinal = horafinal;
    }

    @XmlElement
    public Usuario getUsuario() {
        return usuario;
    }

    public void setUsuario(Usuario usuario) {
        this.usuario = usuario;
    }

    @XmlElement
    public Privacidad getIdprivacidad() {
        return idprivacidad;
    }

    public void setIdprivacidad(Privacidad idprivacidad) {
        this.idprivacidad = idprivacidad;
    }

    @XmlElement
    public Periodicidad getIdperiodicidad() {
        return idperiodicidad;
    }

    public void setIdperiodicidad(Periodicidad idperiodicidad) {
        this.idperiodicidad = idperiodicidad;
    }

    @XmlElement
    public Repeticion getRepeticion() {
        return repeticion;
    }

    public void setRepeticion(Repeticion repeticion) {
        this.repeticion = repeticion;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (citaPK != null ? citaPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Cita)) {
            return false;
        }
        Cita other = (Cita) object;
        if ((this.citaPK == null && other.citaPK != null) || (this.citaPK != null && !this.citaPK.equals(other.citaPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entity.Cita[ citaPK=" + citaPK + " ]";
    }
    
}
